<?php
/**
 * @Copyright   2008, XXXX-XXXX
 * All rights reserved. 
 * feature summary.
 * @filesource  InitPlayerCommand.php 
 * @author      lipeng <lipengage@gmain.com> 
 * @package     / 
 * @version     $Id: $ 
 */

class InitPlayerCommand extends command{
	public function excute() {
		$userdb = new user_dao();
		$viewerid = $this->request['vid'];
		$container = $this->request['ctn'];
		$name = empty($this->request['name']) ? "":$this->request["name"];
		$photourl = $this->request['photoUrl'];
		if (empty($viewerid) || empty($container) || empty($name)) {
			$this->set_response("messageId", command::$PARAM_ERROR);
			return true;
		}

		$viewer = $userdb->user_get_byid($container, $viewerid);
		if ($viewer['count'] > 0) {
			$this->set_messageid(command::$ALREADY_HAVE_SLAVE);
			return true;
		}
		else {
			$fields = array(
				"container" => $container,
				"uid" => $viewerid,
				"photourl" => $photourl,
				"name" => $name,
				"cash" => $this->config["init_cash"][0],
				"price" => $this->config["init_price"][0],
				"capital" => $this->config["init_cash"][0],
				"slave_num" => 0,
			);
			$rt = $userdb->user_insert($fields);
			if ($rt['rowcount'] > 0) {
				$this->set_haserror(false);
				$fields["masterid"] = "";
				$fields["mastername"] = "";
				$fields["slavenum"] = 0;
				$fields["userId"] = $fields["uid"];
				$this->set_data($viewerid,$fields);
			}
			else {
				return true;
			}
		}
		return false;
	}
}
?>